package csu.edu.flatprogram.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import csu.edu.flatprogram.common.CommonResponse;
import csu.edu.flatprogram.entity.Product;
import csu.edu.flatprogram.persistence.ProductMapper;
import csu.edu.flatprogram.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("productService")
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public CommonResponse<List<Product>> getProductListByCategoryId(String categoryId){
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category",categoryId);
        //此处省略了参数验证
        List<Product> productList = productMapper.selectList(queryWrapper);
        if (productList.isEmpty()){
            return CommonResponse.createForSuccessMessage("没有分类数据");
        }
        return CommonResponse.createForSuccess(productList);
    }
    @Override
    public CommonResponse<Product> getProductById(String productId){
        Product product = productMapper.selectById(productId);
        if (product==null){
            return CommonResponse.createForSuccessMessage("没有数据");
        }
        return CommonResponse.createForSuccess(product);
    }

}
